Find/Replace text in an Edit control
#Include <GuiEdit.au3>
_GUICtrlEditFind(ByRef $h_gui, ByRef $h_edit[, $b_replace = False[, $s_WinTitle = ""[, $s_WinText = ""]]])
Parameters
h_gui | GUI ID/Window Handle (Handle only be used with external controls) |
$h_edit | control ID/Control Handle (Handle only be used with external controls) |
$b_replace | Optional: Boolean True/False show replace option (Default is False) |
$s_WinTitle | Optional: Window Title (should only be used with external controls) |
$s_WinText | Optional: Window Text (should only be used with external controls) |
Return Value
Remarks
Be careful using the $s_WinText
Related
_GUICtrlEditReplaceSel, _GUICtrlEditGetSel, _GUICtrlEditSetSel
Example
Opt("MustDeclareVars", 1)
#include <GUIConstants.au3>
#include <GuiEdit.au3>
; *******************************************************
; Example 1 - Using with an AutoIt Created Edit control
; *******************************************************
_UseAutoItControl()
Func _UseAutoItControl()
Local $s_texttest = "this is a test" & @CRLF & _
"this is only a test" & @CRLF & _
"this testing should work for you as well as it does for me"
Local $GuiCtrlEditSearch, $myEdit, $Button1, $Button2, $msg
$GuiCtrlEditSearch = GUICreate('Find And Replace Example with AutoIt ' & FileGetVersion(@AutoItExe), 622, 448, 192, 125)
$myEdit = GUICtrlCreateEdit($s_texttest, 64, 24, 505, 233, _
BitOR($ES_AUTOVSCROLL, $WS_VSCROLL, $ES_MULTILINE, $WS_HSCROLL, $ES_NOHIDESEL))
$Button1 = GUICtrlCreateButton("Find", 176, 288, 121, 33, 0)
$Button2 = GUICtrlCreateButton("Find And Replace", 368, 288, 121, 33, 0)
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button1
_GUICtrlEditFind ($GuiCtrlEditSearch, $myEdit)
Case $msg = $Button2
_GUICtrlEditFind ($GuiCtrlEditSearch, $myEdit, True)
Case Else
;;;;;;;
EndSelect
WEnd
GUIDelete()
EndFunc ;==>_UseAutoItControl
; *******************************************************
; Example 2 - Using with an external Edit control
; *******************************************************
_UseExternalControl()
Func _UseExternalControl()
Local $s_texttest = 'Find And Replace Example with AutoIt ' & FileGetVersion(@AutoItExe) & @LF & _
"this is a test" & @LF & _
"this is only a test" & @LF & _
"this testing should work for you as well as it does for me"
Local $whandle, $handle
Local $Title = "Untitled - Notepad"
Run("notepad", "", @SW_MAXIMIZE)
;Wait for the window "Untitled" to exist
WinWait($Title)
; Get the handle of a notepad window
$whandle = WinGetHandle($Title)
If @error Then
MsgBox(4096, "Error", "Could not find the correct window")
Else
$handle = ControlGetHandle($whandle, "", "Edit1")
If @error Then
MsgBox(4096, "Error", "Could not find the correct control")
Else
; Send some text directly to this window's edit control
ControlSend($whandle, "", "Edit1", $s_texttest)
_GUICtrlEditFind ($whandle, $handle, True, $Title)
EndIf
EndIf
EndFunc ;==>_UseExternalControl